<!--
  ~ Copyright (c) 2020 the original author or authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      https://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  ~ or implied. See the License for the specific language governing
  ~ permissions and limitations under the License.
  -->

<div class="dialog" mat-dialog>
  <div mat-dialog-header class="dialog__header">
    <h1 mat-dialog-title class="dialog__header--title">{{ 'common.create' | translate }} {{ data.entityType }}</h1>
  </div>
  <form #form="ngForm">
    <div class="dialog__content">
      <div class="form-field">
        <label>{{ data.placeholder }}</label>
        <input
          matInput
          cdkFocusInitial
          (input)="onChange(data.entityName)"
          [ngModelOptions]="{ standalone: true }"
          [(ngModel)]="data.entityName"
          placeholder="{{ data.placeholder }}"
        />
        <div class="err">
          <ng-container *ngIf="alreadyExists">
            {{ data.errorMsg }}
          </ng-container>
          <ng-container *ngIf="data.entityName?.length > maxInputLength && !isForbiddenChar">
            {{ 'common.input_lengh_err' | translate }}
          </ng-container>
          <ng-container *ngIf="isForbiddenChar">
            {{ 'common.forbiden_chars_err' | translate }}
          </ng-container>
        </div>
      </div>
    </div>
    <div mat-dialog-actions class="dialog__actions">
      <button type="button" class="cancel-btn" mat-dialog-close>
        {{ 'common.capital.cancel' | translate | titlecase }}
      </button>
      <button
        type="submit"
        [mat-dialog-close]="data.entityName"
        class="save-btn"
        [disabled]="!data.entityName || alreadyExists || data.entityName.length > maxInputLength || isForbiddenChar"
      >
        {{ 'common.capital.create' | translate | titlecase }}
      </button>
    </div>
  </form>
  <button class="button-cross" mat-icon-button mat-dialog-close>
    <mat-icon svgIcon="cross_new" inline="true"></mat-icon>
  </button>
</div>
